package org.example.game.history;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/05/25 22:47
 */
public class Solution100313 {


    public static void main(String[] args) {
        Solution100313 solution100313 = new Solution100313();
        int limit = 4;
        int[][] queries = new int[][]{{1,4},{2,5},{1,3},{3,4}};
        int[] res = solution100313.queryResults(limit, queries);

        for(int n : res){
            System.out.print(n + " ");
        }

    }


    public int[] queryResults(int limit, int[][] queries) {
        int[] res = new int[queries.length];

        // 有几种颜色
        // 数字对应的颜色
        // 颜色对应的个数

        List<Integer> colourList = new ArrayList<>();
        HashMap<Integer, Integer> indexMapColour = new HashMap<>();
        HashMap<Integer, Integer> colourMapCount = new HashMap<>();


        for(int i=0;i<queries.length;i++){

            int index = queries[i][0];
            int colour = queries[i][1];

            // index 去色
            if(indexMapColour.containsKey(index)){
                Integer oldColour = indexMapColour.get(index);
                colourMapCount.put(oldColour, colourMapCount.get(oldColour) - 1);
                if(colourMapCount.get(oldColour) == 0){
                    colourList.remove(oldColour);
                }
            }

            // index 染色
            indexMapColour.put(index , colour);
            int count = 1;
            if(colourMapCount.containsKey(colour)){
                count += colourMapCount.get(colour);
            }
            colourMapCount.put(colour, count);
            if(count == 1){
                colourList.add(colour);
            }

            res[i] = colourList.size();

        }

        return res;
    }

}
